

package cn.logicalthing.demo.web.controller;

import cn.logicalthing.demo.web.error.CommonErrorCode;
import cn.logicalthing.demo.web.error.RequestBean;
import com.core.bean.Goods;
import com.core.service.AddGoodsService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GoodsController {


    @PostMapping ("/addGoods")
    public RequestBean addGoods(Goods goods) {
        if (goods.getPrice() == null || goods.getPid() == null) {
            return new RequestBean(CommonErrorCode.E_1001);
        }
        try {
            AddGoodsService addGoodsService = new AddGoodsService();
            addGoodsService.save(goods);
        } catch (Exception e) {
            return new RequestBean(CommonErrorCode.E_1000);
        }
        return new RequestBean("添加成功！");
    }

}

